//
//  JGShareViewController.m
//  WangYLottery
//
//  Created by JJetGu on 15/8/29.
//  Copyright (c) 2015年 JJetGu. All rights reserved.

//  友盟APP－key ： 55eac02be0f55a362d00c40a

#import "JGShareViewController.h"

#import "JGSettingItem.h"
#import "JGSettingGroup.h"

#import "JGSettingArrowItem.h"

#import "UMSocial.h"

#import <MessageUI/MessageUI.h>

@interface JGShareViewController ()<MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate>

@end

@implementation JGShareViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self addGroup0];
}

- (void)addGroup0
{
    //0组
    JGSettingArrowItem *sina = [JGSettingArrowItem itemWithIcon:@"WeiboSina" title:@"新浪分享"];
    sina.option = ^(){
        [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina] content:@"分享内嵌文字" image:nil location:nil urlResource:nil completion:^(UMSocialResponseEntity *response) {
            if (response.responseCode == UMSResponseCodeSuccess) {
                NSLog(@"分享成功！");
            }
        }];
    };
    
  JGSettingItem *sms = [JGSettingArrowItem itemWithIcon:@"SmsShare" title:@"短信分享"];
     __weak JGShareViewController *share = self;
    sms.option = ^(){
        if (![MFMessageComposeViewController canSendSubject]) return ;
        MFMessageComposeViewController *vc = [[MFMessageComposeViewController alloc] init];
        // 设置短信内容
        vc.body = @"吃饭了没？";
        // 设置收件人列表
        vc.recipients = @[@"10010", @"02010010"];
        // 设置代理
        vc.messageComposeDelegate = share;
        // 显示控制器
        [share presentViewController:vc animated:YES completion:nil];
    };
    
    JGSettingItem *mail = [JGSettingArrowItem itemWithIcon:@"MailShare" title:@"邮件分享"];
    mail.option = ^(){
        // 不能发邮件
        if (![MFMailComposeViewController canSendMail]) return;
        
        MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];
        // 设置邮件主题
        [vc setSubject:@"会议"];
        // 设置邮件内容
        [vc setMessageBody:@"今天下午开会吧" isHTML:NO];
        // 设置收件人列表
        [vc setToRecipients:@[@"643055866@qq.com"]];
        // 设置抄送人列表
        [vc setCcRecipients:@[@"1234@qq.com"]];
        // 设置密送人列表
        [vc setBccRecipients:@[@"56789@qq.com"]];
        
        //添加附件（一张图片）
        UIImage *image = [UIImage imageNamed:@"阿狸头像"];
        NSData *data = UIImagePNGRepresentation(image);
        [vc addAttachmentData:data mimeType:@"image/png" fileName:@"阿狸头像.png"];
        
        // 设置代理
        vc.mailComposeDelegate = share;
        // 显示控制器
        [self presentViewController:vc animated:YES completion:nil];

    };
    
    JGSettingGroup *group0 = [[JGSettingGroup alloc] init];
    group0.items = @[sina,sms,mail];
    [self.dataList addObject:group0];
}

-(void)dealloc
{
    NSLog(@"dealloc");
}


// 当你取消发送短信的时候就会调用
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
     [self dismissViewControllerAnimated:YES completion:nil];
}


-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
